package cn.icanci.loopstack.pcc.test.meta;

import cn.icanci.loopstack.pcc.model.MetaCell;
import cn.icanci.loopstack.pcc.test.key.KeyEnum;
import cn.icanci.loopstack.pcc.test.order.Order;
import cn.icanci.loopstack.pcc.test.req.CouponReq;
import cn.icanci.loopstack.pcc.test.resp.CouponResp;

import java.util.function.Function;

/**
 * @author icanci
 * @since 1.0 Created in 2024/08/02 15:22
 */
public class CouponMetaCell extends MetaCell<CouponReq, CouponResp, Order> {

    public CouponMetaCell(CouponReq couponReq, Function<CouponReq, CouponResp> function) {
        super(couponReq, function);
    }

    /**
     * 返回元组唯一Key，其在每个组中是唯一的
     *
     * @return 元组唯一Key
     */
    @Override
    public String uniqueKey() {
        return KeyEnum.COUPON.name();
    }

    @Override
    public Order adapter(CouponResp couponResp) {
        Order order = new Order();
        order.setTraceId(couponResp.getTraceId());
        order.setOrderSerialNo(couponResp.getOrderSerialNo());
        order.setPrice(couponResp.getCouponPrice());
        return order;
    }
}
